Merging Smart-seq2 and 10X Datasets
We have quality-controlled the 10X data and the SS2 data and now are left with the following objects:
10X 5K data - pb_sex_filtered
10X 30K data - pb_30k_sex_filtered
SS2 mutant data - ss2_mutants_final
[1] "patchwork is loaded correctly"
[1] "viridis is loaded correctly"
[1] "Seurat is loaded correctly"
[1] "cowplot is loaded correctly"
[1] "gridExtra is loaded correctly"
[1] "grid is loaded correctly"
[1] "Hmisc is loaded correctly"
[1] "reshape2 is loaded correctly"
[1] "dplyr is loaded correctly"
screen hits
## EDIT - change this to the excel table once we have it finalised for the screen
screen_hits <- c("PBANKA-0516300",
"PBANKA-1217700",
"PBANKA-0409100",
"PBANKA-1034300",
"PBANKA-1437500",
"PBANKA-0827500",
"PBANKA-0824300",
"PBANKA-1426900",
"PBANKA-0105300",
"PBANKA-0921100",
"PBANKA-1002400",
"PBANKA-0829400",
"PBANKA-1347200",
"PBANKA-0828000",
"PBANKA-0902300",
"PBANKA-1418100",
"PBANKA-1435200",
"PBANKA-1454800",
"PBANKA-0712300",
"PBANKA-0410500",
"PBANKA-1144800",
"PBANKA-1231600",
"PBANKA-0503200",
"PBANKA-0308900",
"PBANKA-1214700",
"PBANKA-0709900",
"PBANKA-0311900",
"PBANKA-0716500",
"PBANKA-1447900",
"PBANKA-0102200",
"PBANKA-0713500",
"PBANKA-0102400",
"PBANKA-1302700",
"PBANKA-1235900",
"PBANKA-0401100",
"PBANKA-0413400",
"PBANKA-1126900",
"PBANKA-1425900",
"PBANKA-0418300",
"PBANKA-1464600",
"PBANKA-0806000")
load in datasets
## load the 10X dataset
pb_sex_filtered <- readRDS("../data_to_export/pb_sex_filtered.RDS")
#pb_sex_filtered <- readRDS("/Users/Andy/pb_sex_filtered.RDS")
pb_sex_filtered <- readRDS("../data_to_export/pb_sex_filtered.RDS")
## load the SS2 dataset
ss2_mutants_final <- readRDS("../data_to_export/ss2_mutants_final.RDS")
## inspect
paste("10x dataset")
[1] "10x dataset"
pb_sex_filtered
An object of class Seurat
5098 features across 6191 samples within 1 assay
Active assay: RNA (5098 features, 2000 variable features)
2 dimensional reductions calculated: pca, umap
paste("Smart-seq2 dataset")
[1] "Smart-seq2 dataset"
ss2_mutants_final
An object of class Seurat
5245 features across 2970 samples within 1 assay
Active assay: RNA (5245 features, 2000 variable features)
2 dimensional reductions calculated: pca, umap
paste("The composition of the Smart-seq2 dataset is:")
[1] "The composition of the Smart-seq2 dataset is:"
table(ss2_mutants_final@meta.data$genotype)
Mutant WT
2281 689
## extract 10x data
tenx_5k_counts <- as.matrix(pb_sex_filtered@assays$RNA@counts)
tenx_5k_pheno <- pb_sex_filtered@meta.data
## Create fresh object
tenx_5k_counts_to_integrate <- CreateSeuratObject(counts = tenx_5k_counts, meta.data = tenx_5k_pheno, min.cells = 0, min.features = 0, project = "GCSKO")
## add experiment meta data
tenx_5k_counts_to_integrate@meta.data$experiment <- "tenx_5k"
## inspect
tenx_5k_counts_to_integrate
An object of class Seurat
5098 features across 6191 samples within 1 assay
Active assay: RNA (5098 features, 0 variable features)
We need to make sure the mutant data is compatible with the 10X data. the 10X data has fewer genes represented so we need to find the intersect of the two before integration.
## extract SS2 data
mutant_counts_for_integration <- as.matrix(ss2_mutants_final@assays$RNA@counts)
mutant_pheno_for_integration <- ss2_mutants_final@meta.data
## change counts so the :rRNA and :tRNA are not there:
rownames(mutant_counts_for_integration) <- gsub(":ncRNA", "", gsub(":rRNA", "", gsub(":tRNA", "", rownames(mutant_counts_for_integration))))
## change the gene names so that they are - rather than _:
rownames(mutant_counts_for_integration) <- gsub("_", "-", rownames(mutant_counts_for_integration))
## calculate how many of the genes overlap - 10x does start out with 5098 vs 5245
genes_in_tenx_dataset <- intersect(rownames(tenx_5k_counts), rownames(mutant_counts_for_integration))
## print number of genes that overlap
dim(mutant_counts_for_integration)
[1] 5245 2970
## subset the mutant counts to contain only 10x genes
mutant_counts_for_integration <- mutant_counts_for_integration[which(rownames(mutant_counts_for_integration) %in% genes_in_tenx_dataset), ]
## print result of genes that overlap
dim(mutant_counts_for_integration)
[1] 5018 2970
## make Seurat object:
GCSKO_mutants <- CreateSeuratObject(counts = mutant_counts_for_integration, meta.data = mutant_pheno_for_integration, min.cells = 0, min.features = 0, project = "GCSKO")
## add experiment meta data
GCSKO_mutants@meta.data$experiment <- "mutants"
## inspect
GCSKO_mutants
An object of class Seurat
5018 features across 2970 samples within 1 assay
Active assay: RNA (5018 features, 0 variable features)
## double check that this is the same number of genes
## subset counts so that only genes represented in the other two objects are there:
length(intersect(rownames(tenx_5k_counts), rownames(mutant_counts_for_integration)))
[1] 5018
create list and normalise:
## make list
tenx.mutant.list <- list(tenx_5k_counts_to_integrate, GCSKO_mutants)
## prepare data
for (i in 1:length(tenx.mutant.list)) {
tenx.mutant.list[[i]] <- NormalizeData(tenx.mutant.list[[i]], verbose = FALSE)
tenx.mutant.list[[i]] <- FindVariableFeatures(tenx.mutant.list[[i]], selection.method = "vst",
nfeatures = 2000, verbose = FALSE)
}
## Find anchors
tenx.mutant.anchors <- FindIntegrationAnchors(object.list = tenx.mutant.list, dims = 1:21, verbose = FALSE)
## Integrate data
tenx.mutant.integrated <- IntegrateData(anchorset = tenx.mutant.anchors, dims = 1:21, verbose = FALSE, features.to.integrate = genes_in_tenx_dataset)
Adding a command log without an assay associated with it
## Make the default assay integrated
DefaultAssay(tenx.mutant.integrated) <- "integrated"
## Run the standard workflow for visualization and clustering
tenx.mutant.integrated <- ScaleData(tenx.mutant.integrated, verbose = FALSE)
tenx.mutant.integrated <- RunPCA(tenx.mutant.integrated, npcs = 30, verbose = FALSE)
## inspect PCs
ElbowPlot(tenx.mutant.integrated, ndims = 30, reduction = "pca")
Run inital UMAP
## Run UMAP
tenx.mutant.integrated <- RunUMAP(tenx.mutant.integrated, reduction = "pca", dims = 1:8, n.neighbors = 50, seed.use = 1234, min.dist = 0.5, repulsion.strength = 0.05)
15:40:41 UMAP embedding parameters a = 0.583 b = 1.334
Found more than one class "dist" in cache; using the first, from namespace 'spam'
Also defined by ‘BiocGenerics’
15:40:41 Read 9161 rows and found 8 numeric columns
15:40:41 Using Annoy for neighbor search, n_neighbors = 50
Found more than one class "dist" in cache; using the first, from namespace 'spam'
Also defined by ‘BiocGenerics’
15:40:41 Building Annoy index with metric = cosine, n_trees = 50
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
15:40:44 Writing NN index file to temp file /var/folders/wj/rztzclxn1t10cl2sk0plbf3r0000gn/T//RtmpXGhNV1/file43372b7bbd87
15:40:44 Searching Annoy index using 1 thread, search_k = 5000
15:40:49 Annoy recall = 100%
15:40:50 Commencing smooth kNN distance calibration using 1 thread
15:40:52 Initializing from normalized Laplacian + noise
15:40:54 Commencing optimization for 500 epochs, with 599738 positive edges
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
15:41:09 Optimization finished
See distribution by: altogether, experiment, and mutant ID
## Plot
DimPlot(tenx.mutant.integrated, reduction = "umap", pt.size = 0.01)
DimPlot(tenx.mutant.integrated, reduction = "umap", split.by = "experiment", pt.size = 0.01)
DimPlot(tenx.mutant.integrated, reduction = "umap", group.by = "identity_updated", label = TRUE, repel = TRUE, pt.size = 0.01)
After optimisation, the following UMAP can be calculated:
## Run optimised UMAP
tenx.mutant.integrated <- RunUMAP(tenx.mutant.integrated, reduction = "pca", dims = 1:10, n.neighbors = 150, seed.use = 1234, min.dist = 0.4, repulsion.strength = 0.03, local.connectivity = 150)
15:41:13 UMAP embedding parameters a = 0.7669 b = 1.223
Found more than one class "dist" in cache; using the first, from namespace 'spam'
Also defined by ‘BiocGenerics’
15:41:13 Read 9161 rows and found 10 numeric columns
15:41:13 Using Annoy for neighbor search, n_neighbors = 150
Found more than one class "dist" in cache; using the first, from namespace 'spam'
Also defined by ‘BiocGenerics’
15:41:13 Building Annoy index with metric = cosine, n_trees = 50
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
15:41:15 Writing NN index file to temp file /var/folders/wj/rztzclxn1t10cl2sk0plbf3r0000gn/T//RtmpXGhNV1/file433748d8005e
15:41:15 Searching Annoy index using 1 thread, search_k = 15000
15:41:27 Annoy recall = 100%
15:41:28 Commencing smooth kNN distance calibration using 1 thread
15:41:28 9161 smooth knn distance failures
15:41:32 Initializing from normalized Laplacian + noise
15:41:34 Commencing optimization for 500 epochs, with 1845842 positive edges
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
15:46:23 Optimization finished
## plot
dp1 <- DimPlot(tenx.mutant.integrated, label = TRUE, repel = FALSE, pt.size = 0.05, dims = c(2,1), group.by = "experiment") +
## fix the axis
coord_fixed() +
## reverse the scale
scale_x_reverse()
## view
dp1
Now store these reversed embeddings in a new slot
## extract the cell embeddings from the UMAP
mds <- as.data.frame(tenx.mutant.integrated@reductions$umap@cell.embeddings)
## change the coordinates of UMAP 2 so they are reversed
mds$UMAP_2 <- -mds$UMAP_2
## change names of the cols
colnames(mds) <- paste0("DIM_UMAP_", 1:2)
## make into a matrix so that it can be saved in Seurat
mds <- as.matrix(mds)
## store this optimsed UMAP in a custom dim slot
tenx.mutant.integrated[["DIM_UMAP"]] <- CreateDimReducObject(embeddings = mds, key = "DIM_UMAP_", assay = DefaultAssay(tenx.mutant.integrated))
Keys should be one or more alphanumeric characters followed by an underscore, setting key from DIM_UMAP_ to DIMUMAP_All keys should be one or more alphanumeric characters followed by an underscore '_', setting key to DIMUMAP_
## check
DimPlot(tenx.mutant.integrated, label = TRUE, repel = FALSE, pt.size = 0.05, dims = c(2,1), reduction = "DIM_UMAP") + coord_fixed()
Recluster dataset now that it is integrated. We will cluster with a number of resolutions to begin with to see how this affects the number and nature of the clusters.
## copy old clusters
tenx.mutant.integrated <- AddMetaData(tenx.mutant.integrated, tenx.mutant.integrated@meta.data$RNA_snn_res.1, col.name = "pre_integration_clusters")
## generate new clusters at low resolution
## 1
tenx.mutant.integrated <- FindNeighbors(tenx.mutant.integrated, dims = 1:15)
Computing nearest neighbor graph
Computing SNN
tenx.mutant.integrated <- FindClusters(tenx.mutant.integrated, resolution = 1, random.seed = 42, algorithm = 2)
Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
Number of nodes: 9161
Number of edges: 327141
Running Louvain algorithm with multilevel refinement...
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Maximum modularity in 10 random starts: 0.8681
Number of communities: 20
Elapsed time: 1 seconds
## generate new clusters at low resolution
## 1.2
tenx.mutant.integrated <- FindNeighbors(tenx.mutant.integrated, dims = 1:15)
Computing nearest neighbor graph
Computing SNN
tenx.mutant.integrated <- FindClusters(tenx.mutant.integrated, resolution = 1.2, random.seed = 42, algorithm = 2)
Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
Number of nodes: 9161
Number of edges: 327141
Running Louvain algorithm with multilevel refinement...
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Maximum modularity in 10 random starts: 0.8542
Number of communities: 22
Elapsed time: 1 seconds
## generate new clusters at low resolution
## 1.5
tenx.mutant.integrated <- FindNeighbors(tenx.mutant.integrated, dims = 1:15)
Computing nearest neighbor graph
Computing SNN
tenx.mutant.integrated <- FindClusters(tenx.mutant.integrated, resolution = 1.5, random.seed = 42, algorithm = 2)
Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
Number of nodes: 9161
Number of edges: 327141
Running Louvain algorithm with multilevel refinement...
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Maximum modularity in 10 random starts: 0.8366
Number of communities: 25
Elapsed time: 1 seconds
## generate new clusters at mid resolution
## 2
tenx.mutant.integrated <- FindNeighbors(tenx.mutant.integrated, dims = 1:15)
Computing nearest neighbor graph
Computing SNN
tenx.mutant.integrated <- FindClusters(tenx.mutant.integrated, resolution = 2, random.seed = 42, algorithm = 2)
Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
Number of nodes: 9161
Number of edges: 327141
Running Louvain algorithm with multilevel refinement...
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Maximum modularity in 10 random starts: 0.8125
Number of communities: 31
Elapsed time: 1 seconds
## generate new clusters at high resolution
## 4
tenx.mutant.integrated <- FindNeighbors(tenx.mutant.integrated, dims = 1:15)
Computing nearest neighbor graph
Computing SNN
tenx.mutant.integrated <- FindClusters(tenx.mutant.integrated, resolution = 4, random.seed = 42, algorithm = 2)
Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
Number of nodes: 9161
Number of edges: 327141
Running Louvain algorithm with multilevel refinement...
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Maximum modularity in 10 random starts: 0.7435
Number of communities: 45
Elapsed time: 1 seconds
## print identities
#head(Idents(tenx.mutant.integrated), 10)
View
## Plot
DimPlot(tenx.mutant.integrated, label = TRUE, repel = TRUE, pt.size = 0.05, dims = c(2,1), reduction = "DIM_UMAP", group.by = "integrated_snn_res.1") + coord_fixed()
Make individual plots highlighting where cells in each cluster fall
plot
## this function writes the next bit of code for you
## put it into the console and paste the response
#ploty <- c()
#for(i in seq_along(levels(tenx.mutant.integrated@meta.data$seurat_clusters))){
# ploty <- paste0(ploty, "list_UMAPs_by_cluster[[", i, "]]", " + ")
#}
## plot
list_UMAPs_by_cluster[[1]] + list_UMAPs_by_cluster[[2]] + list_UMAPs_by_cluster[[3]] + list_UMAPs_by_cluster[[4]] + list_UMAPs_by_cluster[[5]] + list_UMAPs_by_cluster[[6]] + list_UMAPs_by_cluster[[7]] + list_UMAPs_by_cluster[[8]] + list_UMAPs_by_cluster[[9]] + list_UMAPs_by_cluster[[10]] + list_UMAPs_by_cluster[[11]] + list_UMAPs_by_cluster[[12]] + list_UMAPs_by_cluster[[13]] + list_UMAPs_by_cluster[[14]] + list_UMAPs_by_cluster[[15]] + list_UMAPs_by_cluster[[16]] + list_UMAPs_by_cluster[[17]] + list_UMAPs_by_cluster[[18]] + list_UMAPs_by_cluster[[19]] + list_UMAPs_by_cluster[[20]]
View
## Plot
DimPlot(tenx.mutant.integrated, label = TRUE, repel = TRUE, pt.size = 0.05, dims = c(2,1), reduction = "DIM_UMAP", group.by = "integrated_snn_res.1.2") + coord_fixed()
Make individual plots highlighting where cells in each cluster fall
plot
## this function writes the next bit of code for you
## put it into the console and paste the response
#ploty <- c()
#for(i in seq_along(levels(tenx.mutant.integrated@meta.data$seurat_clusters))){
# ploty <- paste0(ploty, "list_UMAPs_by_cluster[[", i, "]]", " + ")
#}
## plot
list_UMAPs_by_cluster[[1]] + list_UMAPs_by_cluster[[2]] + list_UMAPs_by_cluster[[3]] + list_UMAPs_by_cluster[[4]] + list_UMAPs_by_cluster[[5]] + list_UMAPs_by_cluster[[6]] + list_UMAPs_by_cluster[[7]] + list_UMAPs_by_cluster[[8]] + list_UMAPs_by_cluster[[9]] + list_UMAPs_by_cluster[[10]] + list_UMAPs_by_cluster[[11]] + list_UMAPs_by_cluster[[12]] + list_UMAPs_by_cluster[[13]] + list_UMAPs_by_cluster[[14]] + list_UMAPs_by_cluster[[15]] + list_UMAPs_by_cluster[[16]] + list_UMAPs_by_cluster[[17]] + list_UMAPs_by_cluster[[18]] + list_UMAPs_by_cluster[[19]] + list_UMAPs_by_cluster[[20]] + list_UMAPs_by_cluster[[21]] + list_UMAPs_by_cluster[[22]]
## Plot
DimPlot(tenx.mutant.integrated, label = TRUE, repel = TRUE, pt.size = 0.05, dims = c(2,1), reduction = "DIM_UMAP", group.by = "integrated_snn_res.1.5") + coord_fixed()
Make individual plots highlighting where cells in each cluster fall
## 1.5 resolution
list_UMAPs_by_cluster[[1]] + list_UMAPs_by_cluster[[2]] + list_UMAPs_by_cluster[[3]] + list_UMAPs_by_cluster[[4]] + list_UMAPs_by_cluster[[5]] + list_UMAPs_by_cluster[[6]] + list_UMAPs_by_cluster[[7]] + list_UMAPs_by_cluster[[8]] + list_UMAPs_by_cluster[[9]] + list_UMAPs_by_cluster[[10]] + list_UMAPs_by_cluster[[11]] + list_UMAPs_by_cluster[[12]] + list_UMAPs_by_cluster[[13]] + list_UMAPs_by_cluster[[14]] + list_UMAPs_by_cluster[[15]] + list_UMAPs_by_cluster[[16]] + list_UMAPs_by_cluster[[17]] + list_UMAPs_by_cluster[[18]] + list_UMAPs_by_cluster[[19]] + list_UMAPs_by_cluster[[20]] + list_UMAPs_by_cluster[[21]] + list_UMAPs_by_cluster[[22]] + list_UMAPs_by_cluster[[23]] + list_UMAPs_by_cluster[[24]] + list_UMAPs_by_cluster[[25]]
View
## Plot
DimPlot(tenx.mutant.integrated, label = TRUE, repel = TRUE, pt.size = 0.05, dims = c(2,1), reduction = "DIM_UMAP", group.by = "integrated_snn_res.2") + coord_fixed()
Make individual plots highlighting where cells in each cluster fall
plot
## this function writes the next bit of code for you
## put it into the console and paste the response
#ploty <- c()
#for(i in seq_along(levels(tenx.mutant.integrated@meta.data$seurat_clusters))){
# ploty <- paste0(ploty, "list_UMAPs_by_cluster[[", i, "]]", " + ")
#}
## plot
list_UMAPs_by_cluster[[1]] + list_UMAPs_by_cluster[[2]] + list_UMAPs_by_cluster[[3]] + list_UMAPs_by_cluster[[4]] + list_UMAPs_by_cluster[[5]] + list_UMAPs_by_cluster[[6]] + list_UMAPs_by_cluster[[7]] + list_UMAPs_by_cluster[[8]] + list_UMAPs_by_cluster[[9]] + list_UMAPs_by_cluster[[10]] + list_UMAPs_by_cluster[[11]] + list_UMAPs_by_cluster[[12]] + list_UMAPs_by_cluster[[13]] + list_UMAPs_by_cluster[[14]] + list_UMAPs_by_cluster[[15]] + list_UMAPs_by_cluster[[16]] + list_UMAPs_by_cluster[[17]] + list_UMAPs_by_cluster[[18]] + list_UMAPs_by_cluster[[19]] + list_UMAPs_by_cluster[[20]] + list_UMAPs_by_cluster[[21]] + list_UMAPs_by_cluster[[22]] + list_UMAPs_by_cluster[[23]] + list_UMAPs_by_cluster[[24]] + list_UMAPs_by_cluster[[25]] + list_UMAPs_by_cluster[[26]] + list_UMAPs_by_cluster[[27]] + list_UMAPs_by_cluster[[28]] + list_UMAPs_by_cluster[[29]] + list_UMAPs_by_cluster[[30]] + list_UMAPs_by_cluster[[31]]
3 vs 19 on resolution 2 already looks pretty cool:
## reset the default identity
## generate new clusters at mid resolution
## 2
tenx.mutant.integrated <- FindNeighbors(tenx.mutant.integrated, dims = 1:15)
Computing nearest neighbor graph
Computing SNN
tenx.mutant.integrated <- FindClusters(tenx.mutant.integrated, resolution = 2, random.seed = 42, algorithm = 2)
Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
Number of nodes: 9161
Number of edges: 327141
Running Louvain algorithm with multilevel refinement...
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Maximum modularity in 10 random starts: 0.8125
Number of communities: 31
Elapsed time: 1 seconds
## Find deferentially expressed features between the two clusters
early.sex.de.markers <- FindMarkers(tenx.mutant.integrated, ident.1 = "5", ident.2 = "3")
| | 0 % ~calculating
|+ | 1 % ~17s
|++ | 2 % ~17s
|++ | 3 % ~17s
|+++ | 4 % ~16s
|+++ | 5 % ~16s
|++++ | 6 % ~15s
|++++ | 7 % ~15s
|+++++ | 8 % ~14s
|+++++ | 9 % ~13s
|++++++ | 10% ~13s
|++++++ | 11% ~12s
|+++++++ | 12% ~12s
|+++++++ | 13% ~11s
|++++++++ | 14% ~11s
|++++++++ | 15% ~10s
|+++++++++ | 16% ~10s
|+++++++++ | 17% ~10s
|++++++++++ | 18% ~10s
|++++++++++ | 19% ~10s
|+++++++++++ | 20% ~09s
|+++++++++++ | 21% ~09s
|++++++++++++ | 22% ~09s
|++++++++++++ | 23% ~09s
|+++++++++++++ | 24% ~08s
|+++++++++++++ | 26% ~08s
|++++++++++++++ | 27% ~08s
|++++++++++++++ | 28% ~08s
|+++++++++++++++ | 29% ~08s
|+++++++++++++++ | 30% ~08s
|++++++++++++++++ | 31% ~08s
|++++++++++++++++ | 32% ~08s
|+++++++++++++++++ | 33% ~07s
|+++++++++++++++++ | 34% ~07s
|++++++++++++++++++ | 35% ~07s
|++++++++++++++++++ | 36% ~07s
|+++++++++++++++++++ | 37% ~07s
|+++++++++++++++++++ | 38% ~07s
|++++++++++++++++++++ | 39% ~07s
|++++++++++++++++++++ | 40% ~07s
|+++++++++++++++++++++ | 41% ~07s
|+++++++++++++++++++++ | 42% ~07s
|++++++++++++++++++++++ | 43% ~06s
|++++++++++++++++++++++ | 44% ~06s
|+++++++++++++++++++++++ | 45% ~06s
|+++++++++++++++++++++++ | 46% ~06s
|++++++++++++++++++++++++ | 47% ~06s
|++++++++++++++++++++++++ | 48% ~06s
|+++++++++++++++++++++++++ | 49% ~06s
|+++++++++++++++++++++++++ | 50% ~06s
|++++++++++++++++++++++++++ | 51% ~05s
|+++++++++++++++++++++++++++ | 52% ~05s
|+++++++++++++++++++++++++++ | 53% ~05s
|++++++++++++++++++++++++++++ | 54% ~05s
|++++++++++++++++++++++++++++ | 55% ~05s
|+++++++++++++++++++++++++++++ | 56% ~05s
|+++++++++++++++++++++++++++++ | 57% ~05s
|++++++++++++++++++++++++++++++ | 58% ~04s
|++++++++++++++++++++++++++++++ | 59% ~04s
|+++++++++++++++++++++++++++++++ | 60% ~04s
|+++++++++++++++++++++++++++++++ | 61% ~04s
|++++++++++++++++++++++++++++++++ | 62% ~04s
|++++++++++++++++++++++++++++++++ | 63% ~04s
|+++++++++++++++++++++++++++++++++ | 64% ~04s
|+++++++++++++++++++++++++++++++++ | 65% ~04s
|++++++++++++++++++++++++++++++++++ | 66% ~04s
|++++++++++++++++++++++++++++++++++ | 67% ~04s
|+++++++++++++++++++++++++++++++++++ | 68% ~03s
|+++++++++++++++++++++++++++++++++++ | 69% ~03s
|++++++++++++++++++++++++++++++++++++ | 70% ~03s
|++++++++++++++++++++++++++++++++++++ | 71% ~03s
|+++++++++++++++++++++++++++++++++++++ | 72% ~03s
|+++++++++++++++++++++++++++++++++++++ | 73% ~03s
|++++++++++++++++++++++++++++++++++++++ | 74% ~03s
|++++++++++++++++++++++++++++++++++++++ | 76% ~03s
|+++++++++++++++++++++++++++++++++++++++ | 77% ~03s
|+++++++++++++++++++++++++++++++++++++++ | 78% ~02s
|++++++++++++++++++++++++++++++++++++++++ | 79% ~02s
|++++++++++++++++++++++++++++++++++++++++ | 80% ~02s
|+++++++++++++++++++++++++++++++++++++++++ | 81% ~02s
|+++++++++++++++++++++++++++++++++++++++++ | 82% ~02s
|++++++++++++++++++++++++++++++++++++++++++ | 83% ~02s
|++++++++++++++++++++++++++++++++++++++++++ | 84% ~02s
|+++++++++++++++++++++++++++++++++++++++++++ | 85% ~02s
|+++++++++++++++++++++++++++++++++++++++++++ | 86% ~02s
|++++++++++++++++++++++++++++++++++++++++++++ | 87% ~01s
|++++++++++++++++++++++++++++++++++++++++++++ | 88% ~01s
|+++++++++++++++++++++++++++++++++++++++++++++ | 89% ~01s
|+++++++++++++++++++++++++++++++++++++++++++++ | 90% ~01s
|++++++++++++++++++++++++++++++++++++++++++++++ | 91% ~01s
|++++++++++++++++++++++++++++++++++++++++++++++ | 92% ~01s
|+++++++++++++++++++++++++++++++++++++++++++++++ | 93% ~01s
|+++++++++++++++++++++++++++++++++++++++++++++++ | 94% ~01s
|++++++++++++++++++++++++++++++++++++++++++++++++ | 95% ~01s
|++++++++++++++++++++++++++++++++++++++++++++++++ | 96% ~00s
|+++++++++++++++++++++++++++++++++++++++++++++++++ | 97% ~00s
|+++++++++++++++++++++++++++++++++++++++++++++++++ | 98% ~00s
|++++++++++++++++++++++++++++++++++++++++++++++++++| 99% ~00s
|++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=11s
# view results
head(early.sex.de.markers)
look at them across the dataset
DotPlot(tenx.mutant.integrated, features = c(rownames(early.sex.de.markers[1:10,]), "PBANKA-1302700")) + RotatedAxis()
DotPlot(tenx.mutant.integrated, features = screen_hits) + RotatedAxis()
## find all markers
#all.markers <- FindAllMarkers(tenx.mutant.integrated, only.pos = FALSE, min.pct = 0.25, logfc.threshold = 0.25)
#top_two <- all.markers %>% group_by(cluster) %>% top_n(n = 2, wt = avg_logFC)
top_two
View
## Plot
DimPlot(tenx.mutant.integrated, label = TRUE, repel = TRUE, pt.size = 0.05, dims = c(2,1), reduction = "DIM_UMAP", group.by = "integrated_snn_res.4") + coord_fixed()
Make individual plots highlighting where cells in each cluster fall
plot
## this function writes the next bit of code for you
## put it into the console and paste the response
#ploty <- c()
#for(i in seq_along(levels(tenx.mutant.integrated@meta.data$seurat_clusters))){
# ploty <- paste0(ploty, "list_UMAPs_by_cluster[[", i, "]]", " + ")
#}
## plot
list_UMAPs_by_cluster[[1]] + list_UMAPs_by_cluster[[2]] + list_UMAPs_by_cluster[[3]] + list_UMAPs_by_cluster[[4]] + list_UMAPs_by_cluster[[5]] + list_UMAPs_by_cluster[[6]] + list_UMAPs_by_cluster[[7]] + list_UMAPs_by_cluster[[8]] + list_UMAPs_by_cluster[[9]] + list_UMAPs_by_cluster[[10]] + list_UMAPs_by_cluster[[11]] + list_UMAPs_by_cluster[[12]] + list_UMAPs_by_cluster[[13]] + list_UMAPs_by_cluster[[14]] + list_UMAPs_by_cluster[[15]] + list_UMAPs_by_cluster[[16]] + list_UMAPs_by_cluster[[17]] + list_UMAPs_by_cluster[[18]] + list_UMAPs_by_cluster[[19]] + list_UMAPs_by_cluster[[20]] + list_UMAPs_by_cluster[[21]] + list_UMAPs_by_cluster[[22]] + list_UMAPs_by_cluster[[23]] + list_UMAPs_by_cluster[[24]] + list_UMAPs_by_cluster[[25]] + list_UMAPs_by_cluster[[26]] + list_UMAPs_by_cluster[[27]] + list_UMAPs_by_cluster[[28]] + list_UMAPs_by_cluster[[29]] + list_UMAPs_by_cluster[[30]] + list_UMAPs_by_cluster[[31]] + list_UMAPs_by_cluster[[32]] + list_UMAPs_by_cluster[[33]] + list_UMAPs_by_cluster[[34]] + list_UMAPs_by_cluster[[35]] + list_UMAPs_by_cluster[[36]] + list_UMAPs_by_cluster[[37]] + list_UMAPs_by_cluster[[38]] + list_UMAPs_by_cluster[[39]] + list_UMAPs_by_cluster[[40]] + list_UMAPs_by_cluster[[41]] + list_UMAPs_by_cluster[[42]] + list_UMAPs_by_cluster[[43]] + list_UMAPs_by_cluster[[44]] + list_UMAPs_by_cluster[[45]]
## run a new UMAP with
tenx.mutant.integrated <- RunUMAP(tenx.mutant.integrated, reduction = "pca", dims = 1:10, n.components = 10)
15:48:24 UMAP embedding parameters a = 0.9922 b = 1.112
Found more than one class "dist" in cache; using the first, from namespace 'spam'
Also defined by ‘BiocGenerics’
15:48:24 Read 9161 rows and found 10 numeric columns
15:48:24 Using Annoy for neighbor search, n_neighbors = 30
Found more than one class "dist" in cache; using the first, from namespace 'spam'
Also defined by ‘BiocGenerics’
15:48:24 Building Annoy index with metric = cosine, n_trees = 50
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
15:48:27 Writing NN index file to temp file /var/folders/wj/rztzclxn1t10cl2sk0plbf3r0000gn/T//RtmpXGhNV1/file43371993ff23
15:48:27 Searching Annoy index using 1 thread, search_k = 3000
15:48:30 Annoy recall = 100%
15:48:32 Commencing smooth kNN distance calibration using 1 thread
15:48:35 Initializing from normalized Laplacian + noise
15:48:35 Commencing optimization for 500 epochs, with 374688 positive edges
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
15:48:57 Optimization finished
## generate new clusters at low resolution
tenx.mutant.integrated <- FindNeighbors(tenx.mutant.integrated, dims = 1:10, reduction = "umap")
Computing nearest neighbor graph
Computing SNN
tenx.mutant.integrated <- FindClusters(tenx.mutant.integrated, resolution = 0.5, random.seed = 42, algorithm = 2)
Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
Number of nodes: 9161
Number of edges: 217927
Running Louvain algorithm with multilevel refinement...
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Maximum modularity in 10 random starts: 0.9507
Number of communities: 26
Elapsed time: 0 seconds
[1] 26
plot
## this function writes the next bit of code for you
## put it into the console and paste the response
#ploty <- c()
#for(i in seq_along(levels(tenx.mutant.integrated@meta.data$seurat_clusters))){
# ploty <- paste0(ploty, "list_UMAPs_by_cluster[[", i, "]]", " + ")
#}
## plot
list_UMAPs_by_cluster[[1]] + list_UMAPs_by_cluster[[2]] + list_UMAPs_by_cluster[[3]] + list_UMAPs_by_cluster[[4]] + list_UMAPs_by_cluster[[5]] + list_UMAPs_by_cluster[[6]] + list_UMAPs_by_cluster[[7]] + list_UMAPs_by_cluster[[8]] + list_UMAPs_by_cluster[[9]] + list_UMAPs_by_cluster[[10]] + list_UMAPs_by_cluster[[11]] + list_UMAPs_by_cluster[[12]] + list_UMAPs_by_cluster[[13]] + list_UMAPs_by_cluster[[14]] + list_UMAPs_by_cluster[[15]] + list_UMAPs_by_cluster[[16]] + list_UMAPs_by_cluster[[17]] + list_UMAPs_by_cluster[[18]] + list_UMAPs_by_cluster[[19]] + list_UMAPs_by_cluster[[20]] + list_UMAPs_by_cluster[[21]] + list_UMAPs_by_cluster[[22]] + list_UMAPs_by_cluster[[23]] + list_UMAPs_by_cluster[[24]] + list_UMAPs_by_cluster[[25]] + list_UMAPs_by_cluster[[26]]
We will look in more detail at cells as they enter the sexual trajecotry later. The PCA clustering will be more appropriate in this high-resolution view. In order to subset these cells, we will use the UMAP clustering.
## generate final clusters which will be written into the 'seurat.clusters' slot in meta data
tenx.mutant.integrated <- FindNeighbors(tenx.mutant.integrated, dims = 1:10, reduction = "umap")
Computing nearest neighbor graph
Computing SNN
tenx.mutant.integrated <- FindClusters(tenx.mutant.integrated, resolution = 0.5, random.seed = 42, algorithm = 2)
Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
Number of nodes: 9161
Number of edges: 217927
Running Louvain algorithm with multilevel refinement...
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Maximum modularity in 10 random starts: 0.9507
Number of communities: 26
Elapsed time: 0 seconds
## Plot
DimPlot(tenx.mutant.integrated, label = TRUE, repel = TRUE, pt.size = 0.05, group.by = "seurat_clusters", dims = c(2,1), reduction = "DIM_UMAP") + coord_fixed()
We will get some high level insight into these clusters now
v1 <- VlnPlot(object = tenx.mutant.integrated, features = "nFeature_RNA", group.by = "seurat_clusters", pt.size = 0.01)
v2 <- VlnPlot(object = tenx.mutant.integrated, features = "nCount_RNA", group.by = "seurat_clusters", pt.size = 0.01)
v1 + v2
We have defined clusters, now we will identify what the clusters correspond to. We can use a number of external datasets to do this:
known marker genes
bulk RNA-seq data correlation
## make plots
plots <- FeaturePlot(tenx.mutant.integrated, features = c("PBANKA-1319500", "PBANKA-0416100"), blend = TRUE, combine = FALSE, coord.fixed = TRUE, dims = c(2,1), reduction = "DIM_UMAP")
# Get just the co-expression plot, built-in legend is meaningless for this plot
#plots[[3]] + NoLegend()
# Get just the key
#plots[[4]]
# Stitch the co-expression and key plots together
plots[[3]] + NoLegend() + plots[[4]]/plot_spacer() + plot_layout(widths = c(2,1))
marker genes plots
## find a good ring marker, to see if there is a better one than the ones reported
#markers_ring <- FindMarkers(tenx.mutant.integrated, ident.1 = c("4", "5", "16", "11", "7", "3", "9", "0", "22"))
#head(markers_ring)
# PBANKA-1319500 - CCP2 - female - used in 820 line
# PBANKA-0416100 - MG1 - dynenin heavy chain - male - used in 820 line
# PBANKA-1437500 - AP2G - commitment
# PBANKA-0831000 - MSP1 - late asexual
# PBANKA-1102200 - MSP8 - early asexual (from Bozdech paper)
# PBANKA-0711900 - HSP70 - promoter used for GFP and RFP expression in the mutants
# PBANKA-1400400 - FAMB - ring marker - discovered by looking for marker genes in data
# PBANKA-0722600 - Fam-b2 - ring marker - https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5113031/
marker_gene_plot_CCP2 <- FeaturePlot(tenx.mutant.integrated, features = "PBANKA-1319500", coord.fixed = TRUE, min.cutoff = "q1", dims = c(2,1), reduction = "DIM_UMAP", pt.size = 1, order = TRUE) +
theme_void() +
labs(title = paste("CCP2 (Female)")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold")) +
scale_colour_gradientn(colours=c("#DCDCDC", plasma(30)))
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
marker_gene_plot_MG1 <- FeaturePlot(tenx.mutant.integrated, features = "PBANKA-0416100", coord.fixed = TRUE, min.cutoff = "q1", dims = c(2,1), reduction = "DIM_UMAP", pt.size = 1, order = TRUE) +
theme_void() +
labs(title = paste("MG1 (Male)")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold")) +
scale_colour_gradientn(colours=c("#DCDCDC", plasma(30)))
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
marker_gene_plot_AP2G <- FeaturePlot(tenx.mutant.integrated, features = "PBANKA-1437500", coord.fixed = TRUE, min.cutoff = "q1", dims = c(2,1), reduction = "DIM_UMAP", pt.size = 1, order = TRUE) +
theme_void() +
labs(title = paste("AP2G (Commitment)")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold")) +
scale_colour_gradientn(colours=c("#DCDCDC", plasma(30)))
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
marker_gene_plot_MSP1 <- FeaturePlot(tenx.mutant.integrated, features = "PBANKA-0831000", coord.fixed = TRUE, min.cutoff = "q1", dims = c(2,1), reduction = "DIM_UMAP", pt.size = 1, order = TRUE) +
theme_void() +
labs(title = paste("MSP1 (Schizont)")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold")) +
scale_colour_gradientn(colours=c("#DCDCDC", plasma(30)))
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
marker_gene_plot_MSP8 <- FeaturePlot(tenx.mutant.integrated, features = "PBANKA-1102200", coord.fixed = TRUE, min.cutoff = "q1", dims = c(2,1), reduction = "DIM_UMAP", pt.size = 1, order = TRUE) +
theme_void() +
labs(title = paste("MSP8 (Asexual)")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold")) +
scale_colour_gradientn(colours=c("#DCDCDC", plasma(30)))
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
marker_gene_plot_SBP1 <- FeaturePlot(tenx.mutant.integrated, features = "PBANKA-1101300", coord.fixed = TRUE, min.cutoff = "q1", dims = c(2,1), reduction = "DIM_UMAP", pt.size = 1, order = TRUE) +
theme_void() +
labs(title = paste("SBP1 (Ring)")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold")) +
scale_colour_gradientn(colours=c("#DCDCDC", plasma(30)))
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
marker_gene_plot_FAMB <- FeaturePlot(tenx.mutant.integrated, features = "PBANKA-0722600", coord.fixed = TRUE, min.cutoff = "q1", dims = c(2,1), reduction = "DIM_UMAP", pt.size = 1, order = TRUE) +
theme_void() +
labs(title = paste("Fam-b2 (Ring)")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold")) +
scale_colour_gradientn(colours=c("#DCDCDC", plasma(30)))
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
marker_gene_plot_HSP70 <- FeaturePlot(tenx.mutant.integrated, features = "PBANKA-0711900", coord.fixed = TRUE, min.cutoff = "q1", dims = c(2,1), reduction = "DIM_UMAP", pt.size = 1, order = TRUE) +
theme_void() +
labs(title = paste("(HSP70; Reporter)","\n", "PBANKA_0711900")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold")) +
scale_colour_gradientn(colours=c("#DCDCDC", plasma(30)))
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
##original label:
# labs(title = paste("(CCP2; Female)","\n", "PBANKA_1319500"))
## plot
marker_gene_plot_FAMB + marker_gene_plot_MSP8 + marker_gene_plot_MSP1 + marker_gene_plot_AP2G + marker_gene_plot_CCP2 + marker_gene_plot_MG1 + marker_gene_plot_HSP70
Then define each cluster as Male, Female or Asexual:
## copy clusters to new column
tenx.mutant.integrated@meta.data$cluster_colours_figure <- NA
## define which clusters will be which identity
male_clusters <- c("20", "17", "8", "18")
female_clusters <- c("23", "19", "21", "5")
asex_clusters <- c("6", "4", "9", "2", "1", "7", "0", "3", "12", "16", "10", "11", "24", "14", "15", "22", "25")
bipotential_clusters <- c("13")
## check length of the unique entries in the manualy created list above and the number of clusters in total
paste("Is the total number of clusters in the list the same as the number of clusters in the slot?", identical(length(unique(c(male_clusters, female_clusters, asex_clusters, bipotential_clusters))), length(levels(tenx.mutant.integrated@meta.data$seurat_clusters))))
[1] "Is the total number of clusters in the list the same as the number of clusters in the slot? TRUE"
## change the column IDs
tenx.mutant.integrated@meta.data$cluster_colours_figure[which(tenx.mutant.integrated@meta.data$seurat_clusters %in% male_clusters)] <- "Male"
tenx.mutant.integrated@meta.data$cluster_colours_figure[which(tenx.mutant.integrated@meta.data$seurat_clusters %in% female_clusters)] <- "Female"
tenx.mutant.integrated@meta.data$cluster_colours_figure[which(tenx.mutant.integrated@meta.data$seurat_clusters %in% asex_clusters)] <- "Asexual"
tenx.mutant.integrated@meta.data$cluster_colours_figure[which(tenx.mutant.integrated@meta.data$seurat_clusters %in% bipotential_clusters)] <- "Bipotential"
table(tenx.mutant.integrated@meta.data$cluster_colours_figure)
Asexual Bipotential Female Male
7008 222 1044 887
useful tools for all plots
## define male and female symbol
female_symbol <- intToUtf8(9792)
male_symbol <- intToUtf8(9794)
save
ggsave("../images_to_export/merge_UMAP_identity.png", plot = UMAP_identity, device = "png", path = NULL, scale = 1, width = 20, height = 20, units = "cm", dpi = 300, limitsize = TRUE)
## Plot
umap_cluster <- DimPlot(tenx.mutant.integrated, label = TRUE, label.size = 8, repel = FALSE, pt.size = 0.5, dims = c(2,1), reduction = "DIM_UMAP") +
coord_fixed() +
theme(legend.position="bottom",
axis.line=element_blank(),
axis.text.x=element_blank(),
axis.text.y=element_blank(),
axis.ticks=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank()) +
guides(colour=guide_legend(nrow = 3, byrow = TRUE, override.aes = list(size=5)))
## print
umap_cluster
save
ggsave("../images_to_export/merge_UMAP_cluster.png", plot = umap_cluster, device = "png", path = NULL, scale = 1, width = 20, height = 20, units = "cm", dpi = 300, limitsize = TRUE)
## make plots
## hoo dataset correlation
UMAP_hoo <- DimPlot(tenx.mutant.integrated, label = FALSE, repel = TRUE, pt.size = 0.1, group.by = "Prediction.Spearman.", dims = c(2,1), reduction = "DIM_UMAP") +
coord_fixed() +
theme_void() +
labs(title = paste("Hoo Predicted Timepoint")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold")) +
scale_colour_manual(values = inferno(12)) +
labs(colour = "hour") +
theme(legend.position = "bottom", legend.title=element_text(size=10))
## ap2g timecourse in this paper correlation
UMAP_kasia <- DimPlot(tenx.mutant.integrated, label = FALSE, repel = TRUE, pt.size = 0.1, group.by = "Prediction.Spearman._Kasia", dims = c(2,1), reduction = "DIM_UMAP") +
coord_fixed() +
theme_void() +
labs(title = paste("AP2G Timecourse Predicted Timepoint")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold")) +
scale_colour_manual(values = inferno(10)) +
labs(colour = "hour") +
theme(legend.position = "bottom", legend.title=element_text(size=10))
## combine
umap_bulk <- wrap_plots(UMAP_hoo, UMAP_kasia, ncol = 2)
## print
umap_bulk
ggsave("../images_to_export/merge_umap_bulk_prediction.png", plot = umap_bulk, device = "png", path = NULL, scale = 1, width = 30, height = 10, units = "cm", dpi = 300, limitsize = TRUE)
The original method of plotting by experiment does not allow much customisation of the plots. I.e. we cannot easily change the titles of each plot
## Plot
DimPlot(tenx.mutant.integrated, label = TRUE, repel = TRUE, pt.size = 0.5, split.by = "experiment", dims = c(2,1), reduction = "DIM_UMAP") +
coord_fixed() +
theme(legend.position="bottom", axis.line=element_blank(),axis.text.x=element_blank(),
axis.text.y=element_blank(),axis.ticks=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank())
But, we can use the following code to do this
## make an extra meta.data column so you can split the object by SS2 mutant, SS2 WT, 10X
## make new column in meta.data
tenx.mutant.integrated@meta.data$sub_genotype <- tenx.mutant.integrated@meta.data$genotype
## replace NA values from 10X data with a value
tenx.mutant.integrated@meta.data$sub_genotype[is.na(tenx.mutant.integrated@meta.data$sub_genotype)] <- "10X_WT"
## check
table(tenx.mutant.integrated@meta.data$sub_genotype)
10X_WT Mutant WT
6191 2281 689
## split seurat object up
ob.list <- SplitObject(tenx.mutant.integrated, split.by = "sub_genotype")
## make plots for each object
plot.list <- lapply(X = ob.list, FUN = function(x) {
DimPlot(x, dims = c(2,1), reduction = "DIM_UMAP", label = FALSE, label.size = 5, repel = TRUE, pt.size = 1) + theme(legend.position="bottom")
})
## use this function to extract legend:
## source: https://stackoverflow.com/questions/13649473/add-a-common-legend-for-combined-ggplots
## source: https://github.com/hadley/ggplot2/wiki/Share-a-legend-between-two-ggplot2-graphs
g_legend<-function(a.gplot){
tmp <- ggplot_gtable(ggplot_build(a.gplot))
leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
legend <- tmp$grobs[[leg]]
return(legend)}
## make plots pretty
p1 <- plot.list$`10X_WT` + theme_void() + guides(colour=guide_legend(nrow=2,byrow=TRUE, override.aes = list(size=4)))
p2 <- plot.list$WT + theme_void()
p3 <- plot.list$Mutant + theme_void()
## get legend
mylegend<-g_legend(p1)
## make a final plot
p4 <- grid.arrange(arrangeGrob(p1 + theme(legend.position="none") + labs(title = paste("10X", "\n", "(wild-type)")) + theme(plot.title = element_text(hjust = 0.5)),
p2 + theme(legend.position="none") + labs(title = paste("Smart-seq2", "\n", "(wild-type)")) + theme(plot.title = element_text(hjust = 0.5)),
p3 + theme(legend.position="none") + labs(title = paste("Smart-seq2", "\n", "(mutant)")) + theme(plot.title = element_text(hjust = 0.5)), nrow=1),
mylegend, nrow=2,heights=c(10, 1))
Make final plots:
p1 <- plot.list$`10X_WT` +
coord_fixed() +
theme_void() +
scale_color_manual(values=c(replicate(45, "#999999"))) +
labs(title = paste("10X (wild-type)")) +
theme(legend.position = "none", plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold"))
p2 <- plot.list$WT +
coord_fixed() +
theme_void() +
scale_color_manual(values=c(replicate(46, "#999999"))) +
labs(title = paste("Smart-seq2 (wild-type)")) +
theme(legend.position = "none", plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold"))
p3 <- plot.list$Mutant +
coord_fixed() +
theme_void() +
scale_color_manual(values=c(replicate(46, "#999999"))) +
labs(title = paste("Smart-seq2 (mutant)")) +
theme(legend.position = "none", plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold"))
p1 + p2 + p3
## make composite plot
UMAP_composite <- wrap_plots(marker_gene_plot_FAMB , marker_gene_plot_MSP8 , marker_gene_plot_MSP1 , marker_gene_plot_AP2G , marker_gene_plot_CCP2 , marker_gene_plot_MG1 , p1 , p2 , p3, ncol = 3)
## print
UMAP_composite
save
ggsave("../images_to_export/merge_umap_technology_and_markers.png", plot = UMAP_composite, device = "png", path = NULL, scale = 1, width = 30, height = 30, units = "cm", dpi = 300, limitsize = TRUE)
Specific gene expression of mutants
# PBANKA-1418100 GCSKO-17 FD3
# PBANKA-0102400 GCSKO-2 MD3
# PBANKA-0716500 GCSKO-19 MD4
# PBANKA-1435200 GCSKO-20 FD4
# PBANKA-0902300 GCSKO-13 FD2
# PBANKA-0413400 GCSKO-10_820 MD5
# PBANKA-0828000 GCSKO-3 GD1
# PBANKA-1302700 GCSKO-oom MD1
# PBANKA-1447900 GCSKO-29 MD2
# PBANKA-1454800 GCSKO-21 FD1
# PBANKA-1144800 GCSKO-28 FD5
marker_gene_plot_17 <- FeaturePlot(tenx.mutant.integrated, dims = c(2,1), reduction = "DIM_UMAP", features = "PBANKA-1418100", coord.fixed = TRUE, min.cutoff = "q10", max.cutoff = "q95", pt.size = 1, order = TRUE) +
theme_void() +
labs(title = paste("17")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold")) +
scale_colour_gradientn(colours=c("#DCDCDC", plasma(30))) +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
marker_gene_plot_2 <- FeaturePlot(tenx.mutant.integrated, dims = c(2,1), reduction = "DIM_UMAP", features = "PBANKA-0102400", coord.fixed = TRUE, min.cutoff = "q10", max.cutoff = "q95", pt.size = 1, order = TRUE) +
theme_void() +
labs(title = paste("2")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold")) +
scale_colour_gradientn(colours=c("#DCDCDC", plasma(30))) +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
marker_gene_plot_19 <- FeaturePlot(tenx.mutant.integrated, dims = c(2,1), reduction = "DIM_UMAP", features = "PBANKA-0716500", coord.fixed = TRUE, min.cutoff = "q10", max.cutoff = "q95", pt.size = 1, order = TRUE) +
theme_void() +
labs(title = paste("19")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold")) +
scale_colour_gradientn(colours=c("#DCDCDC", plasma(30))) +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
marker_gene_plot_20 <- FeaturePlot(tenx.mutant.integrated, dims = c(2,1), reduction = "DIM_UMAP", features = "PBANKA-1435200", coord.fixed = TRUE, min.cutoff = "q10", max.cutoff = "q95", pt.size = 1, order = TRUE) +
theme_void() +
labs(title = paste("20")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold")) +
scale_colour_gradientn(colours=c("#DCDCDC", plasma(30))) +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
marker_gene_plot_13 <- FeaturePlot(tenx.mutant.integrated, dims = c(2,1), reduction = "DIM_UMAP", features = "PBANKA-0902300", coord.fixed = TRUE, min.cutoff = "q10", max.cutoff = "q95", pt.size = 1, order = TRUE) +
theme_void() +
labs(title = paste("13")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold")) +
scale_colour_gradientn(colours=c("#DCDCDC", plasma(30))) +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
marker_gene_plot_10 <- FeaturePlot(tenx.mutant.integrated, dims = c(2,1), reduction = "DIM_UMAP", features = "PBANKA-0413400", coord.fixed = TRUE, min.cutoff = "q10", max.cutoff = "q95", pt.size = 1, order = TRUE) +
theme_void() +
labs(title = paste("10")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold")) +
scale_colour_gradientn(colours=c("#DCDCDC", plasma(30))) +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
marker_gene_plot_3 <- FeaturePlot(tenx.mutant.integrated, dims = c(2,1), reduction = "DIM_UMAP", features = "PBANKA-0828000", coord.fixed = TRUE, min.cutoff = "q10", max.cutoff = "q95", pt.size = 1, order = TRUE) +
theme_void() +
labs(title = paste("3")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold")) +
scale_colour_gradientn(colours=c("#DCDCDC", plasma(30))) +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
marker_gene_plot_oom <- FeaturePlot(tenx.mutant.integrated, dims = c(2,1), reduction = "DIM_UMAP", features = "PBANKA-1302700", coord.fixed = TRUE, min.cutoff = "q10", max.cutoff = "q95", pt.size = 1, order = TRUE) +
theme_void() +
labs(title = paste("oom")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold")) +
scale_colour_gradientn(colours=c("#DCDCDC", plasma(30))) +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
marker_gene_plot_29 <- FeaturePlot(tenx.mutant.integrated, dims = c(2,1), reduction = "DIM_UMAP", features = "PBANKA-1447900", coord.fixed = TRUE, min.cutoff = "q10", max.cutoff = "q95", pt.size = 1, order = TRUE) +
theme_void() +
labs(title = paste("29")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold")) +
scale_colour_gradientn(colours=c("#DCDCDC", plasma(30))) +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
marker_gene_plot_21 <- FeaturePlot(tenx.mutant.integrated, dims = c(2,1), reduction = "DIM_UMAP", features = "PBANKA-1454800", coord.fixed = TRUE, min.cutoff = "q10", max.cutoff = "q95", pt.size = 1, order = TRUE) +
theme_void() +
labs(title = paste("21")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold")) +
scale_colour_gradientn(colours=c("#DCDCDC", plasma(30))) +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
marker_gene_plot_28 <- FeaturePlot(tenx.mutant.integrated, dims = c(2,1), reduction = "DIM_UMAP", features = "PBANKA-1144800", coord.fixed = TRUE, min.cutoff = "q10", max.cutoff = "q95", pt.size = 1, order = TRUE) +
theme_void() +
labs(title = paste("28")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 20, face = "bold")) +
scale_colour_gradientn(colours=c("#DCDCDC", plasma(30))) +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
##original label:
# labs(title = paste("(CCP2; Female)","\n", "PBANKA_1319500"))
## make composite plot
mutant_expression_composite <- wrap_plots(marker_gene_plot_17 , marker_gene_plot_2 , marker_gene_plot_19 , marker_gene_plot_20 , marker_gene_plot_13 , marker_gene_plot_10 , marker_gene_plot_3 , marker_gene_plot_oom , marker_gene_plot_29 , marker_gene_plot_21 , marker_gene_plot_28, ncol = 4)
## print
mutant_expression_composite
save
ggsave("../images_to_export/merge_umap_mutant_gene_expression.png", plot = mutant_expression_composite, device = "png", path = NULL, scale = 1, width = 30, height = 30, units = "cm", dpi = 300, limitsize = TRUE)
All the mutant genotypes profiled were:
## make a list of possible genotypes
unique(tenx.mutant.integrated@meta.data$identity_updated)
[1] NA "GCSKO-oom" "WT" "GCSKO-29"
[5] "GCSKO-21" "GCSKO-28" "GCSKO-17" "GCSKO-2"
[9] "GCSKO-19" "GCSKO-20" "GCSKO-13" "GCSKO-10_820"
[13] "GCSKO-3"
## ~ TODO ~ MAKE INTO A FOR LOOP
## make lists for each genotype
cells_17 <- rownames(tenx.mutant.integrated@meta.data[which(tenx.mutant.integrated@meta.data$identity_updated == "GCSKO-17"), ])
cells_2 <- rownames(tenx.mutant.integrated@meta.data[which(tenx.mutant.integrated@meta.data$identity_updated == "GCSKO-2"), ])
cells_19 <- rownames(tenx.mutant.integrated@meta.data[which(tenx.mutant.integrated@meta.data$identity_updated == "GCSKO-19"), ])
cells_20 <- rownames(tenx.mutant.integrated@meta.data[which(tenx.mutant.integrated@meta.data$identity_updated == "GCSKO-20"), ])
cells_13 <- rownames(tenx.mutant.integrated@meta.data[which(tenx.mutant.integrated@meta.data$identity_updated == "GCSKO-13"), ])
cells_10 <- rownames(tenx.mutant.integrated@meta.data[which(tenx.mutant.integrated@meta.data$identity_updated == "GCSKO-10_820"), ])
cells_3 <- rownames(tenx.mutant.integrated@meta.data[which(tenx.mutant.integrated@meta.data$identity_updated == "GCSKO-3"), ])
cells_oom <- rownames(tenx.mutant.integrated@meta.data[which(tenx.mutant.integrated@meta.data$identity_updated == "GCSKO-oom"), ])
cells_29 <- rownames(tenx.mutant.integrated@meta.data[which(tenx.mutant.integrated@meta.data$identity_updated == "GCSKO-29"), ])
cells_21 <- rownames(tenx.mutant.integrated@meta.data[which(tenx.mutant.integrated@meta.data$identity_updated == "GCSKO-21"), ])
cells_28 <- rownames(tenx.mutant.integrated@meta.data[which(tenx.mutant.integrated@meta.data$identity_updated == "GCSKO-28"), ])
## make plots
pm1 <- DimPlot(tenx.mutant.integrated, label = FALSE, repel = TRUE, pt.size = 0.1, cells.highlight = cells_28, group.by = "exclude_for_sex_ratio", dims = c(2,1), reduction = "DIM_UMAP") +
coord_fixed() +
scale_color_manual(values=c("#000000", "#f54e1e")) +
theme_void() +
labs(title = paste("Mutant 28","\n", "(PBANKA_1144800)")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 15, face = "bold"), legend.position = "none") +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
pm2 <- DimPlot(tenx.mutant.integrated, label = FALSE, repel = TRUE, pt.size = 0.1, cells.highlight = cells_17, group.by = "exclude_for_sex_ratio", dims = c(2,1), reduction = "DIM_UMAP") +
coord_fixed() +
scale_color_manual(values=c("#000000", "#f54e1e")) +
theme_void() +
labs(title = paste("Mutant 17","\n", "(PBANKA_1418100)")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 15, face = "bold"), legend.position = "none") +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
pm3 <- DimPlot(tenx.mutant.integrated, label = FALSE, repel = TRUE, pt.size = 0.1, cells.highlight = cells_2, group.by = "exclude_for_sex_ratio", dims = c(2,1), reduction = "DIM_UMAP") +
coord_fixed() +
scale_color_manual(values=c("#000000", "#f54e1e")) +
theme_void() +
labs(title = paste("Mutant 2","\n", "(PBANKA_0102400)")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 15, face = "bold"), legend.position = "none") +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
pm4 <- DimPlot(tenx.mutant.integrated, label = FALSE, repel = TRUE, pt.size = 0.1, cells.highlight = cells_19, group.by = "exclude_for_sex_ratio", dims = c(2,1), reduction = "DIM_UMAP") +
coord_fixed() +
scale_color_manual(values=c("#000000", "#f54e1e")) +
theme_void() +
labs(title = paste("Mutant 19","\n", "(PBANKA_0716500)")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 15, face = "bold"), legend.position = "none") +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
pm5 <- DimPlot(tenx.mutant.integrated, label = FALSE, repel = TRUE, pt.size = 0.1, cells.highlight = cells_20, group.by = "exclude_for_sex_ratio", dims = c(2,1), reduction = "DIM_UMAP") +
coord_fixed() +
scale_color_manual(values=c("#000000", "#f54e1e")) +
theme_void() +
labs(title = paste("Mutant 20","\n", "(PBANKA_1435200)")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 15, face = "bold"), legend.position = "none") +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
pm6 <- DimPlot(tenx.mutant.integrated, label = FALSE, repel = TRUE, pt.size = 0.1, cells.highlight = cells_13, group.by = "exclude_for_sex_ratio", dims = c(2,1), reduction = "DIM_UMAP") +
coord_fixed() +
scale_color_manual(values=c("#000000", "#f54e1e")) +
theme_void() +
labs(title = paste("Mutant 13","\n", "PBANKA_0902300")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 15, face = "bold"), legend.position = "none") +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
pm7 <- DimPlot(tenx.mutant.integrated, label = FALSE, repel = TRUE, pt.size = 0.1, cells.highlight = cells_10, group.by = "exclude_for_sex_ratio", dims = c(2,1), reduction = "DIM_UMAP") +
coord_fixed() +
scale_color_manual(values=c("#000000", "#f54e1e")) +
theme_void() +
labs(title = paste("Mutant 10","\n", "(PBANKA_0413400)")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 15, face = "bold"), legend.position = "none") +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
pm8 <- DimPlot(tenx.mutant.integrated, label = FALSE, repel = TRUE, pt.size = 0.1, cells.highlight = cells_3, group.by = "exclude_for_sex_ratio", dims = c(2,1), reduction = "DIM_UMAP") +
coord_fixed() +
scale_color_manual(values=c("#000000", "#f54e1e")) +
theme_void() +
labs(title = paste("Mutant 3","\n", "(PBANKA_0828000)")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 15, face = "bold"), legend.position = "none") +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
pm9 <- DimPlot(tenx.mutant.integrated, label = FALSE, repel = TRUE, pt.size = 0.1, cells.highlight = cells_oom, group.by = "exclude_for_sex_ratio", dims = c(2,1), reduction = "DIM_UMAP") +
coord_fixed() +
scale_color_manual(values=c("#000000", "#f54e1e")) +
theme_void() +
labs(title = paste("Mutant oom","\n", "(PBANKA_1302700)")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 15, face = "bold"), legend.position = "none") +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
pm10 <- DimPlot(tenx.mutant.integrated, label = FALSE, repel = TRUE, pt.size = 0.1, cells.highlight = cells_29, group.by = "exclude_for_sex_ratio", dims = c(2,1), reduction = "DIM_UMAP") +
coord_fixed() +
scale_color_manual(values=c("#000000", "#f54e1e")) +
theme_void() +
labs(title = paste("Mutant 29","\n", "(PBANKA_1447900)")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 15, face = "bold"), legend.position = "none") +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
pm11 <- DimPlot(tenx.mutant.integrated, label = FALSE, repel = TRUE, pt.size = 0.1, cells.highlight = cells_21, group.by = "exclude_for_sex_ratio", dims = c(2,1), reduction = "DIM_UMAP") +
coord_fixed() +
scale_color_manual(values=c("#000000", "#f54e1e")) +
theme_void() +
labs(title = paste("Mutant 21","\n", "(PBANKA_1454800)")) +
theme(plot.title = element_text(hjust = 0.5, family="Arial", size = 15, face = "bold"), legend.position = "none") +
## add sex symbols
annotate("text", x = 3.8, y = 1.5, label = male_symbol, size=7, color="gray") +
annotate("text", x = 2, y = 2.8, label = female_symbol, size=7, color="gray")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
## plot composite plot
## not used as outside plots have odd sizes
#pm1 + pm2 + pm4 + pm5 + pm11 + pm7 + pm6 + pm8 + pm9 + pm10 + pm3
## plot composite plot
mutant_cell_locations <- plot_grid(pm1 + theme(plot.margin = unit(c(0, 0, 0, 0), "cm")), pm2 + theme(plot.margin = unit(c(0, 0, 0, 0), "cm")), pm4 + theme(plot.margin = unit(c(0, 0, 0, 0), "cm")), pm5 + theme(plot.margin = unit(c(0, 0, 0, 0), "cm")), pm11 + theme(plot.margin = unit(c(0, 0, 0, 0), "cm")), pm7 + theme(plot.margin = unit(c(0, 0, 0, 0), "cm")), pm6 + theme(plot.margin = unit(c(0, 0, 0, 0), "cm")), pm8 + theme(plot.margin = unit(c(0, 0, 0, 0), "cm")), pm9 + theme(plot.margin = unit(c(0, 0, 0, 0), "cm")), pm10 + theme(plot.margin = unit(c(0, 0, 0, 0), "cm")), pm3+ theme(plot.margin = unit(c(0, 0, 0, 0), "cm")), nrow = 3)
## print
mutant_cell_locations
save
ggsave("/Users/Andy/GCSKO/GCSKO_analysis_git/images_to_export/merge_umap_mutant_cell_locations.png", plot = mutant_cell_locations, device = "png", path = NULL, scale = 1, width = 30, height = 30, units = "cm", dpi = 300, limitsize = TRUE)
We will use the following marker genes:
# PBANKA-1319500 - CCP2 - female - used in 820 line
# PBANKA-0416100 - MG1 - dynenin heavy chain - male - used in 820 line
# PBANKA-0831000 - MSP1 - late asexual
# PBANKA-1102200 - MSP8 - early asexual (from Bozdech paper)
# PBANKA-1437500 - AP2G - commitment
plot expression of these marker genes in each cluster
## copy the clusters so you don't permanently edit the master
tenx.mutant.integrated@meta.data$seurat_clusters_plotting <- tenx.mutant.integrated@meta.data$seurat_clusters
## reorder the levels so you can plot the cluters as you wish
my_levels <- c(asex_clusters, bipotential_clusters, male_clusters, female_clusters)
## reorder the levels
tenx.mutant.integrated@meta.data$seurat_clusters_plotting <- factor(x = tenx.mutant.integrated@meta.data$seurat_clusters_plotting, levels = my_levels)
## plot
dot_plot_markers <- DotPlot(tenx.mutant.integrated, features = c("PBANKA-1319500", "PBANKA-0416100", "PBANKA-1437500", "PBANKA-0831000", "PBANKA-1102200"), group.by = "seurat_clusters_plotting") +
theme_classic() +
# change appearance and remove axis elements, and make room for arrows
theme(axis.text.x = element_text(size=16, angle = 45, hjust=1,vjust=1, family = "Arial"), text=element_text(size=16, family="Arial"), legend.position = "bottom", legend.direction = "horizontal", legend.box = "vertical", plot.title = element_blank(), plot.margin = unit(c(1,3,1,3), "lines")) +
#change the colours
scale_colour_viridis(option = "inferno", guide = "colourbar", na.value="white", begin = 0, end = 1, direction = 1) +
## change x axis label
labs(x = "Marker Genes", y = "Cluster", title = "Expression of Marker Genes by Cluster") +
## add arrows
#annotate("segment", x = 5.5, xend = 5.5, y = 21.5, yend = 25, colour = "green", size=1, alpha=1, arrow=arrow(length=unit(0.30,"cm"), type = "closed")) +
#annotate("segment", x = 5.5, xend = 5.5, y = 16.5, yend = 21.5, colour = "red", size=1, alpha=1, arrow=arrow(length=unit(0.30,"cm"), type = "closed")) +
#annotate("segment", x = 5.5, xend = 5.5, y = 0, yend = 15.5, colour = "grey", size=1, alpha=1, arrow=arrow(length=unit(0.30,"cm"), type = "closed")) +
## annotate males
geom_hline(aes(yintercept = 28.5)) +
## annotate females
geom_hline(aes(yintercept = 24.5)) +
## annotate hermaphrodite
geom_hline(aes(yintercept = 23.5)) +
## change label on bottom of plot so we can indicate markers
scale_x_discrete(labels = c(paste("PBANKA-1102200","\n", "(MSP8; early asexual)"), paste("PBANKA-0831000","\n", "(MSP1; late asexual)"), paste("PBANKA-1437500", "\n", "(AP2G; sexual commitment)"), paste("PBANKA-0416100", "\n", "(MG1; male)"), paste("PBANKA-1319500", "\n", "(CCP2; female)")))
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
## view
print(dot_plot_markers)
gene identities for the mutants profiled
# GCSKO-3 PBANKA_0828000
# GCSKO-oom PBANKA_1302700
# GCSKO-29 PBANKA_1447900
# GCSKO-2 PBANKA_0102400
# GCSKO-19 PBANKA_0716500
# GCSKO-20 PBANKA_1435200
# GCSKO-17 PBANKA_1418100
# GCSKO-28 PBANKA_1144800
# GCSKO-13 PBANKA_0902300
# GCSKO-10_820 PBANKA_0413400_820
# GCSKO-21 PBANKA_1454800
plot expression of these mutant genes by cluster
## plot
dot_plot_mutant_genes <- DotPlot(tenx.mutant.integrated, features = c("PBANKA-0828000", "PBANKA-1302700", "PBANKA-1447900", "PBANKA-0102400", "PBANKA-0716500", "PBANKA-1435200", "PBANKA-1418100", "PBANKA-1144800", "PBANKA-0902300", "PBANKA-0413400", "PBANKA-1454800"), group.by = "seurat_clusters_plotting") +
theme_classic() +
## change appearance and remove axis elements, and make room for arrows, and also change posoition of legends relative to one another
theme(axis.text.x = element_text(size=12, angle = 45, hjust=1,vjust=1), legend.position = "bottom", legend.direction = "horizontal", legend.box = "vertical", plot.margin = unit(c(1,3,1,3), "lines"), text=element_text(size=16, family="Arial")) +
##add these to above to remove y = plot.title = element_blank(), axis.text.y = element_blank(), axis.ticks.y = element_blank(), axis.title.y = element_blank()
## change the colours
scale_colour_viridis(option = "inferno", guide = "colourbar", na.value="white", begin = 0, end = 1, direction = 1) +
## change x axis label
labs(x = "Mutant Genes", title = "Expression of mutant genes by cluster", y = "Cluster") +
## annotate males
geom_hline(aes(yintercept = 28.5)) +
## annotate females
geom_hline(aes(yintercept = 24.5)) +
## annotate hermaphrodite
geom_hline(aes(yintercept = 23.5)) +
## change label on bottom of plot so we can indicate markers
scale_x_discrete(labels = c(paste("PBANKA_1454800","\n", "(GCSKO 21)"),
paste("PBANKA-0413400","\n", "(GCSKO 10)"),
paste("PBANKA-0902300", "\n", "(GCSKO 13)"),
paste("PBANKA-1144800", "\n", "(GCSKO 28)"),
paste("PBANKA-1418100", "\n", "(GCSKO 17)"),
paste("PBANKA-1435200", "\n", "(GCSKO 20)"),
paste("PBANKA-0716500", "\n", "(GCSKO 19)"),
paste("PBANKA-0102400", "\n", "(GCSKO 2)"),
paste("PBANKA-1447900", "\n", "(GCSKO 29)"),
paste("PBANKA-1302700", "\n", "(GCSKO oom)"),
paste("PBANKA-0828000", "\n", "(GCSKO 3)")))
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
## view
print(dot_plot_mutant_genes)
make a metadata column where the 10X data is classified as a WT genotype
## get cells that are filtered out
cells_10x <- which(tenx.mutant.integrated@meta.data$experiment == "tenx_5k")
## make extra column in plotting df
tenx.mutant.integrated@meta.data$genotype_combined <- tenx.mutant.integrated@meta.data$genotype
tenx.mutant.integrated@meta.data$genotype_combined[cells_10x] <- "WT"
## inspect
table(tenx.mutant.integrated@meta.data$genotype_combined)
Mutant WT
2281 6880
Plot expression of mutant genes by cluster (which is subdivided by genotype)
This is kind of a control because the mutant should express less of the gene of interest at some point due to the inclusion of the mutant cells
## plot
dot_plot_mutant_genes_genotype <- DotPlot(tenx.mutant.integrated, features = c("PBANKA-0828000", "PBANKA-1302700", "PBANKA-1447900", "PBANKA-0102400", "PBANKA-0716500", "PBANKA-1435200", "PBANKA-1418100", "PBANKA-1144800", "PBANKA-0902300", "PBANKA-0413400", "PBANKA-1454800"), group.by = "seurat_clusters_plotting", split.by = "genotype_combined") +
## make appearance smoother
theme_classic() +
## change appearance and remove axis elements, and make room for arrows
theme(axis.text.x = element_text(size=12, angle = 45, hjust=1,vjust=1), legend.position = "bottom", plot.title = element_blank(), plot.margin = unit(c(1,3,1,1), "lines")) +
## change the colours
#scale_colour_viridis(option = "inferno", guide = "colourbar", na.value="white", begin = 0, end = 1, direction = 1) +
## change x axis label
labs(x = "Marker Genes") +
## annotate males
geom_hline(aes(yintercept = 56.5)) +
## annotate females
geom_hline(aes(yintercept = 48.5)) +
## annotate hermaphrodite
geom_hline(aes(yintercept = 46.5))
## change label on bottom of plot so we can indicate markers
#scale_x_discrete(labels = c(paste("PBANKA-1102200","\n", "(MSP8; early asexual)"), paste("PBANKA-0831000","\n", "(MSP1; late asexual)"), paste("PBANKA-1437500", "\n", "(AP2G; sexual commitment)"), paste("PBANKA-0416100", "\n", "(MG1; male)"), paste("PBANKA-1319500", "\n", "(CCP2; female)")))
## view
print(dot_plot_mutant_genes_genotype)
## plot
dot_plot_mutants_experiment <- DotPlot(tenx.mutant.integrated, features = c("PBANKA-0828000", "PBANKA-1302700", "PBANKA-1447900", "PBANKA-0102400", "PBANKA-0716500", "PBANKA-1435200", "PBANKA-1418100", "PBANKA-1144800", "PBANKA-0902300", "PBANKA-0413400", "PBANKA-1454800"), group.by = "seurat_clusters_plotting", split.by = "sub_genotype", cols = c("red", "blue", "green")) +
theme_classic() +
# change appearance and remove axis elements, and make room for arrows
theme(axis.text.x = element_text(size=12, angle = 45, hjust=1,vjust=1), legend.position = "bottom", plot.title = element_blank(), plot.margin = unit(c(1,3,1,1), "lines")) +
#change the colours
#scale_colour_viridis(option = "inferno", guide = "colourbar", na.value="white", begin = 0, end = 1, direction = 1) +
## change x axis label
labs(x = "Marker Genes") +
## annotate males
geom_hline(aes(yintercept = 77)) +
## annotate females
geom_hline(aes(yintercept = 61)) +
## annotate hermaphrodite
geom_hline(aes(yintercept = 59))
## change label on bottom of plot so we can indicate markers
#scale_x_discrete(labels = c(paste("PBANKA-1102200","\n", "(MSP8; early asexual)"), paste("PBANKA-0831000","\n", "(MSP1; late asexual)"), paste("PBANKA-1437500", "\n", "(AP2G; sexual commitment)"), paste("PBANKA-0416100", "\n", "(MG1; male)"), paste("PBANKA-1319500", "\n", "(CCP2; female)")))
## view
print(dot_plot_mutants_experiment)
Add a meta.data column so that 10X is listed as WT:
## get cells that are filtered out
mutant_cells <- which(tenx.mutant.integrated$experiment == "mutants")
## make extra column in plotting df
tenx.mutant.integrated@meta.data$identity_combined <- "WT_10X"
tenx.mutant.integrated@meta.data$identity_combined[mutant_cells] <- tenx.mutant.integrated@meta.data$identity_updated[mutant_cells]
prepare data for dotplotting
## make a dataframe that is a copy of the meta data
df_meta_data <- as.data.frame(tenx.mutant.integrated@meta.data)
## redefine order of clusters:
df_meta_data$seurat_clusters <- factor(x = df_meta_data$seurat_clusters, levels = my_levels)
## make a new df of CLUSTER and IDENTITY
dot_plot_df <- as.data.frame.matrix(table(df_meta_data$seurat_clusters, df_meta_data$identity_combined))
dot_plot_df$cluster <- rownames(dot_plot_df)
## calculate percentage of cells for each genotype
dot_plot_df_pc <- (as.data.frame.matrix(prop.table(table(df_meta_data$seurat_clusters, df_meta_data$identity_combined), margin = 2)) * 100)
## make a column for cluster names
dot_plot_df_pc$cluster <- rownames(dot_plot_df_pc)
## melt dataframe for plotting
library(reshape2)
dot_plot_df_pc_melted <- melt(dot_plot_df_pc, variable.name = "cluster")
Using cluster as id variables
colnames(dot_plot_df_pc_melted)[2] <- "identity"
## melt the raw number too
dot_plot_df_melted <- melt(dot_plot_df, variable.name = "cluster")
Using cluster as id variables
colnames(dot_plot_df_melted)[2] <- "identity"
colnames(dot_plot_df_melted)[3] <- "raw_number"
## merge together
identical(dot_plot_df_melted$cluster, dot_plot_df_pc_melted$cluster)
[1] TRUE
dot_plot_merged <- cbind(dot_plot_df_melted, dot_plot_df_pc_melted)
dot_plot_merged <- dot_plot_merged[,c(1,2,3,6)]
## redefine order of clusters
dot_plot_merged$cluster <- factor(x = dot_plot_merged$cluster, levels = my_levels)
## where values are zero, add NA
## find wells where it's zero
zero_values <- dot_plot_merged$value == 0
dot_plot_merged$value[zero_values] <- NA
## also do for raw number
zero_values <- dot_plot_merged$raw_number == 0
dot_plot_merged$raw_number[zero_values] <- NA
## reorder x axis:
my_levels_genotype <- c("GCSKO-oom", "GCSKO-29", "GCSKO-3", "GCSKO-2", "GCSKO-19", "GCSKO-28", "GCSKO-21", "GCSKO-13", "GCSKO-17", "GCSKO-20", "GCSKO-10_820", "WT", "WT_10X")
dot_plot_merged$identity <- factor(x = dot_plot_df_pc_melted$identity, levels = my_levels_genotype)
plot
dot_plot_identity <- ggplot(dot_plot_merged, aes(y = factor(cluster), x = factor(identity))) +
## make into a dot plot
geom_point(aes(colour=value, size=raw_number)) +
scale_color_gradient(low="blue", high="red", limits=c( 0, max(dot_plot_df_pc_melted$value)), na.value="white") +
#change the colours
scale_colour_viridis(option = "inferno", guide = "colourbar", na.value="white") +
theme_classic() +
theme(panel.grid.major=element_blank(), panel.grid.minor=element_blank()) +
ylab("Cluster") +
xlab("Identity") +
labs(colour = "% cells of that genotype represented in that cluster", size = "number of cells of that genotype represented in that cluster") +
theme(axis.text.x=element_text(size=12, angle=45, hjust=1, vjust=1), axis.text.y=element_text(size=12), legend.position = "bottom", legend.direction = "horizontal", legend.box = "vertical", text=element_text(size=16, family="Arial")) +
## annotate males
geom_hline(aes(yintercept = 28.5)) +
## annotate females
geom_hline(aes(yintercept = 24.5)) +
## annotate hermaphrodite
geom_hline(aes(yintercept = 23.5))
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
#title = "% genotype population found in each cluster",
print(dot_plot_identity)
maybe the respresentation differences have batch-effects:
#table(tenx.mutant.integrated@meta.data$sort_date, tenx.mutant.integrated@meta.data$identity_updated)
dot_plot_identity + dot_plot_markers + dot_plot_mutant_genes
## plot
dot_plot_paper_figure <- DotPlot(tenx.mutant.integrated,
features = rev(c("PBANKA-1144800", "PBANKA-1435200", "PBANKA-1418100", "PBANKA-0902300", "PBANKA-1454800", "PBANKA-0828000", "PBANKA-0413400", "PBANKA-0716500", "PBANKA-0102400", "PBANKA-1447900", "PBANKA-1302700", "PBANKA-1437500", "PBANKA-0416100", "PBANKA-1300700", "PBANKA-0915000", "PBANKA-1443300", "PBANKA-1145900")), group.by = "seurat_clusters_plotting") +
theme_classic() +
## change appearance and remove axis elements, and make room for arrows, and also change posoition of legends relative to one another
theme(axis.text.x = element_text(size=12, angle = 45, hjust=1,vjust=1), legend.position = "bottom", legend.direction = "horizontal", legend.box = "vertical", plot.margin = unit(c(1,3,1,3), "lines"), text=element_text(size=16, family="Arial")) +
##add these to above to remove y = plot.title = element_blank(), axis.text.y = element_blank(), axis.ticks.y = element_blank(), axis.title.y = element_blank()
## change the colours
scale_colour_viridis(option = "inferno", guide = "colourbar", na.value="white", begin = 0, end = 1, direction = 1) +
## change x axis label
labs(x = "Gene", title = "", y = "Cluster") +
## annotate males
geom_hline(aes(yintercept = 28.5)) +
## annotate females
geom_hline(aes(yintercept = 24.5)) +
## annotate hermaphrodite
geom_hline(aes(yintercept = 23.5)) +
## change label on bottom of plot so we can indicate markers
scale_x_discrete(labels = rev((c(expression(paste(italic("fd5"))),
expression(paste(italic("fd4"))),
expression(paste(italic("fd3"))),
expression(paste(italic("fd2"))),
expression(paste(italic("fd1"))),
expression(paste(italic("gd1"))),
expression(paste(italic("md5"))),
expression(paste(italic("md4"))),
expression(paste(italic("md3"))),
expression(paste(italic("md2"))),
expression(paste(italic("md1"))),
expression(paste(italic("ap2-g"))),
expression(paste(italic("dhc, putative"), "(male)")),
expression(paste(italic("ccp1"), "(female)")),
expression(paste(italic("ama1"), "(schizont)")),
expression(paste(italic("msp9"), "(troph)")),
expression(paste(italic("mahrp1b"), "(ring)"))))))
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
## view
print(dot_plot_paper_figure)
save
ggsave("../images_to_export/merge_dot_plot.png", plot = dot_plot_paper_figure, device = "png", path = NULL, scale = 1, width = 30, height = 35, units = "cm", dpi = 300, limitsize = TRUE)
Make a subsetted Seurat object of sexual cells.
Include the pre-branch too as well as any weird clusters that may have clustered out.
it’s been a while since we looked at the clusters so let’s check them out again:
## Plot
DimPlot(tenx.mutant.integrated, label = TRUE, repel = TRUE, pt.size = 0.05, group.by = "seurat_clusters", dims = c(2,1), reduction = "DIM_UMAP") + coord_fixed()
## define cells
## 2 and 0 are at the beginning of the stalk
sex_clusters <- c(bipotential_clusters, female_clusters, male_clusters, "0", "3")
## subset cells into new object
tenx.mutant.integrated.sex <- subset(tenx.mutant.integrated, idents = sex_clusters)
## inspect object
tenx.mutant.integrated.sex
An object of class Seurat
10116 features across 3700 samples within 2 assays
Active assay: integrated (5018 features, 2000 variable features)
1 other assay present: RNA
3 dimensional reductions calculated: pca, umap, DIM_UMAP
## look at original UMAP
DimPlot(tenx.mutant.integrated.sex, label = TRUE, repel = TRUE, pt.size = 0.1, split.by = "experiment", dims = c(2,1), reduction = "DIM_UMAP") + coord_fixed()
we want to remove:
## look at original UMAP
DimPlot(tenx.mutant.integrated.sex, label = TRUE, repel = TRUE, pt.size = 0.1, dims = c(2,1), reduction = "DIM_UMAP") + coord_fixed() + geom_hline(aes(yintercept = -1.2, alpha = 5)) + geom_vline(aes(xintercept = 0.1, alpha = 5))
## extract cell embeddings
df_sex_cell_embeddings <- as.data.frame(tenx.mutant.integrated.sex@reductions[["DIM_UMAP"]]@cell.embeddings)
## subset anything lower than -0.75 in UMAP 2 and -7 in UMAP 1
remove_cells <- row.names(df_sex_cell_embeddings[which(df_sex_cell_embeddings$DIMUMAP_2 < 0.1 & df_sex_cell_embeddings$DIMUMAP_1 > -1.2), ])
## plot these cells
DimPlot(tenx.mutant.integrated.sex, label = FALSE, repel = TRUE, pt.size = 0.1, cells.highlight = remove_cells, dims = c(2,1), reduction = "DIM_UMAP") +
coord_fixed() +
scale_color_manual(values=c("#000000", "#f54e1e")) +
theme_void() +
#labs(title = paste("(Mutant oom)","\n", "PBANKA_1302700")) +
theme(plot.title = element_text(hjust = 0.5), legend.position = "none")
Scale for 'colour' is already present. Adding another scale for
'colour', which will replace the existing scale.
DimPlot(tenx.mutant.integrated.sex, label = FALSE, repel = TRUE, pt.size = 1, dims = c(2,1), reduction = "DIM_UMAP", group.by = "identity_combined") +
coord_fixed()
then check what the IDs of these cells are to ensure they aren’t a genuine mutant signature
tenx.mutant.integrated.sex@meta.data[rownames(tenx.mutant.integrated.sex@meta.data) %in% remove_cells, ]$identity_combined
[1] "GCSKO-21" "GCSKO-21" "GCSKO-21" "GCSKO-21"
[5] "GCSKO-21" "GCSKO-19" "GCSKO-13" "GCSKO-10_820"
[9] "WT"
Although there are a number of GCSKO-21 cells, there are still many remaining in the sex cluster above and the cells near the asexual cycle also have a GCSKO-17 cell with them and are therefore not exclusively belonging to that mutant so we will remove these cells.
## make keep cells from the remove_cells
## make the not in function
'%ni%' <- Negate('%in%')
keep_cells <- colnames(tenx.mutant.integrated.sex)[which(colnames(tenx.mutant.integrated.sex) %ni% remove_cells)]
## subset
tenx.mutant.integrated.sex <- subset(tenx.mutant.integrated.sex, cells = keep_cells)
## inspect
tenx.mutant.integrated.sex
An object of class Seurat
10116 features across 3691 samples within 2 assays
Active assay: integrated (5018 features, 2000 variable features)
1 other assay present: RNA
3 dimensional reductions calculated: pca, umap, DIM_UMAP
copy old clusters over
## copy old clusters
tenx.mutant.integrated.sex <- AddMetaData(tenx.mutant.integrated.sex, tenx.mutant.integrated.sex@meta.data$seurat_clusters, col.name = "post_integration_clusters")
Save environment
## This saves everything in the global environment for easy recall later
#save.image(file = "GCSKO_merge.RData")
#load(file = "GCSKO_merge.RData")
Save object(s)
## Save an object to a file
saveRDS(tenx.mutant.integrated.sex, file = "../tenx.mutant.integrated.sex.RDS")
## Restore the object
#readRDS(file = "../data_to_export/tenx.mutant.integrated.sex.RDS")
## save integrated object to file
saveRDS(tenx.mutant.integrated, file = "../data_to_export/tenx.mutant.integrated.RDS")
## restore the object
#tenx.mutant.integrated <- readRDS("../data_to_export/tenx.mutant.integrated.RDS")
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats4 parallel grid stats graphics grDevices
[7] utils datasets methods base
other attached packages:
[1] RColorBrewer_1.1-2 SingleCellExperiment_1.10.1
[3] SummarizedExperiment_1.18.2 DelayedArray_0.14.1
[5] matrixStats_0.56.0 GenomicRanges_1.40.0
[7] GenomeInfoDb_1.24.2 IRanges_2.22.2
[9] S4Vectors_0.26.1 Biobase_2.48.0
[11] BiocGenerics_0.34.0 KernSmooth_2.23-17
[13] fields_10.3 maps_3.3.0
[15] spam_2.5-1 dotCall64_1.0-0
[17] mixtools_1.2.0 scales_1.1.1
[19] knitr_1.29 reshape2_1.4.4
[21] Hmisc_4.4-0 Formula_1.2-3
[23] survival_3.2-3 lattice_0.20-41
[25] gridExtra_2.3 dplyr_1.0.0
[27] patchwork_1.0.1 ggplot2bdc_0.3.2
[29] cowplot_1.0.0 ggpubr_0.4.0
[31] ggplot2_3.3.2 viridis_0.5.1
[33] viridisLite_0.3.0 Seurat_3.2.0
loaded via a namespace (and not attached):
[1] reticulate_1.16 tidyselect_1.1.0
[3] htmlwidgets_1.5.1 Rtsne_0.15
[5] devtools_2.3.0 munsell_0.5.0
[7] codetools_0.2-16 ica_1.0-2
[9] future_1.18.0 miniUI_0.1.1.1
[11] withr_2.2.0 colorspace_1.4-1
[13] highr_0.8 rstudioapi_0.11
[15] ROCR_1.0-11 ggsignif_0.6.0
[17] tensor_1.5 listenv_0.8.0
[19] labeling_0.3 GenomeInfoDbData_1.2.3
[21] polyclip_1.10-0 farver_2.0.3
[23] pheatmap_1.0.12 rprojroot_1.3-2
[25] vctrs_0.3.2 generics_0.0.2
[27] xfun_0.15 R6_2.4.1
[29] rsvd_1.0.3 bitops_1.0-6
[31] spatstat.utils_1.17-0 assertthat_0.2.1
[33] promises_1.1.1 nnet_7.3-14
[35] gtable_0.3.0 globals_0.12.5
[37] processx_3.4.3 goftest_1.2-2
[39] rlang_0.4.7 splines_4.0.2
[41] rstatix_0.6.0 lazyeval_0.2.2
[43] acepack_1.4.1 hexbin_1.28.1
[45] broom_0.7.0 checkmate_2.0.0
[47] yaml_2.2.1 abind_1.4-5
[49] crosstalk_1.1.0.1 backports_1.1.8
[51] httpuv_1.5.4 tools_4.0.2
[53] usethis_1.6.1 ellipsis_0.3.1
[55] sessioninfo_1.1.1 ggridges_0.5.2
[57] Rcpp_1.0.5 plyr_1.8.6
[59] zlibbioc_1.34.0 base64enc_0.1-3
[61] RCurl_1.98-1.2 purrr_0.3.4
[63] ps_1.3.3 prettyunits_1.1.1
[65] rpart_4.1-15 deldir_0.1-28
[67] pbapply_1.4-2 zoo_1.8-8
[69] haven_2.3.1 ggrepel_0.8.2
[71] cluster_2.1.0 fs_1.4.2
[73] tinytex_0.25 magrittr_1.5
[75] data.table_1.12.8 RSpectra_0.16-0
[77] openxlsx_4.1.5 lmtest_0.9-37
[79] RANN_2.6.1 fitdistrplus_1.1-1
[81] pkgload_1.1.0 hms_0.5.3
[83] mime_0.9 evaluate_0.14
[85] xtable_1.8-4 rio_0.5.16
[87] jpeg_0.1-8.1 readxl_1.3.1
[89] testthat_2.3.2 compiler_4.0.2
[91] tibble_3.0.3 crayon_1.3.4
[93] htmltools_0.5.0 segmented_1.2-0
[95] mgcv_1.8-31 later_1.1.0.1
[97] tidyr_1.1.0 MASS_7.3-51.6
[99] Matrix_1.2-18 car_3.0-8
[101] cli_2.0.2 igraph_1.2.5
[103] forcats_0.5.0 pkgconfig_2.0.3
[105] foreign_0.8-80 plotly_4.9.2.1
[107] XVector_0.28.0 stringr_1.4.0
[109] callr_3.4.3 digest_0.6.25
[111] sctransform_0.2.1 RcppAnnoy_0.0.16
[113] spatstat.data_1.4-3 rmarkdown_2.3
[115] cellranger_1.1.0 leiden_0.3.3
[117] htmlTable_2.0.1 uwot_0.1.8
[119] curl_4.3 kernlab_0.9-29
[121] shiny_1.5.0 lifecycle_0.2.0
[123] nlme_3.1-148 jsonlite_1.7.0
[125] carData_3.0-4 limma_3.44.3
[127] desc_1.2.0 fansi_0.4.1
[129] pillar_1.4.6 fastmap_1.0.1
[131] httr_1.4.2 pkgbuild_1.1.0
[133] glue_1.4.1 remotes_2.1.1
[135] zip_2.1.0 spatstat_1.64-1
[137] png_0.1-7 stringi_1.4.6
[139] latticeExtra_0.6-29 memoise_1.1.0
[141] irlba_2.3.3 future.apply_1.6.0
[143] ape_5.4
– Subset only 10X cells
– cluster 24 is predetermination cells – cluster 29 is post cells – cluster 36 is post cells
## Subset 10X Dataset, cluster 24
## extract only cells in cluster 24
seurat.object.subset <- SubsetData(tenx.mutant.integrated, subset.name = "seurat_clusters", accept.value = c("24"))
## get the names of the cells in cluster of interest
names_of_cells_in_cluster_24 <- colnames(seurat.object.subset@assays$RNA@counts)
## subset seurat
tenx_cluster_24 <- SubsetData(pb_sex_filtered, cells = names_of_cells_in_cluster_24)
## extract data
tenx_cluster_24_matrix_data <- as(as.matrix(GetAssayData(tenx_cluster_24, assay = "RNA", slot = "data")), 'sparseMatrix')
## extract counts
tenx_cluster_24_matrix_counts <- as(as.matrix(GetAssayData(tenx_cluster_24, assay = "RNA", slot = "counts")), 'sparseMatrix')
## extract meta data
## make big meta data dataframe
meta_df <- data.frame(tenx.mutant.integrated.sex@meta.data)
#meta_df <- data.frame(tenx.mutant.integrated@meta.data)
tenx_cluster_24_pd <- meta_df[which(rownames(meta_df) %in% colnames(tenx_cluster_24_matrix_counts)), ]
# save all 3 files
#write.csv(tenx_cluster_24_matrix_data, file = "~/data_to_export/tenx_cluster_24_matrix_data.csv")
#write.csv(tenx_cluster_24_matrix_counts, file = "~/data_to_export/tenx_cluster_24_matrix_counts.csv")
write.csv(tenx_cluster_24_pd, file = "~/data_to_export/tenx_cluster_24_pd.csv")
## Subset 10X Dataset, cluster 29
# extract only cells in cluster 29
seurat.object.subset <- SubsetData(tenx.mutant.integrated, subset.name = "seurat_clusters", accept.value = c("29"))
#get the names of the cells in cluster of interest
names_of_cells_in_cluster_29 <- colnames(seurat.object.subset@assays$RNA@counts)
# subset seurat
tenx_cluster_29 <- SubsetData(pb_sex_filtered, cells = names_of_cells_in_cluster_29)
# extract data
tenx_cluster_29_matrix_data <- as(as.matrix(GetAssayData(tenx_cluster_29, assay = "RNA", slot = "data")), 'sparseMatrix')
# extract counts
tenx_cluster_29_matrix_counts <- as(as.matrix(GetAssayData(tenx_cluster_29, assay = "RNA", slot = "counts")), 'sparseMatrix')
# extract meta data
tenx_cluster_29_pd <- meta_df[which(rownames(meta_df) %in% colnames(tenx_cluster_29_matrix_counts)), ]
# save all 3 files
#write.csv(tenx_cluster_29_matrix_data, file = "~/data_to_export/tenx_cluster_29_matrix_data.csv")
#write.csv(tenx_cluster_29_matrix_counts, file = "~/data_to_export/tenx_cluster_29_matrix_counts.csv")
write.csv(tenx_cluster_29_pd, file = "~/data_to_export/tenx_cluster_29_pd.csv")
## Subset 10X Dataset, cluster 36
# extract only cells in cluster 36
seurat.object.subset <- SubsetData(tenx.mutant.integrated, subset.name = "seurat_clusters", accept.value = c("36"))
#get the names of the cells in cluster of interest
names_of_cells_in_cluster_36 <- colnames(seurat.object.subset@assays$RNA@counts)
# subset seurat
tenx_cluster_36 <- SubsetData(pb_sex_filtered, cells = names_of_cells_in_cluster_36)
# extract data
tenx_cluster_36_matrix_data <- as(as.matrix(GetAssayData(tenx_cluster_36, assay = "RNA", slot = "data")), 'sparseMatrix')
# extract counts
tenx_cluster_36_matrix_counts <- as(as.matrix(GetAssayData(tenx_cluster_36, assay = "RNA", slot = "counts")), 'sparseMatrix')
# extract meta data
tenx_cluster_36_pd <- meta_df[which(rownames(meta_df) %in% colnames(tenx_cluster_36_matrix_counts)), ]
# save all 3 files
#write.csv(tenx_cluster_36_matrix_data, file = "~/data_to_export/tenx_cluster_36_matrix_data.csv")
#write.csv(tenx_cluster_36_matrix_counts, file = "~/data_to_export/tenx_cluster_36_matrix_counts.csv")
write.csv(tenx_cluster_36_pd, file = "~/data_to_export/tenx_cluster_36_pd.csv")